//应用全局侧边栏设计

// ignore_for_file: non_constant_identifier_names, must_be_immutable

import 'package:flutter/material.dart';
import 'package:project_award_statistics/pages/mobile_material_design/award_profile_edit/profile_edit.dart';
import 'package:project_award_statistics/pages/mobile_material_design/home_page/home_page.dart';
import 'package:project_award_statistics/utils/mobile_material_design/my_drawer/my_list_tile.dart';

class MyDrawer extends StatelessWidget {

  String current_page;  //current_page字符串变量通入用于获取当前所在页面
  String stu_name;

  MyDrawer({
    super.key,
    required this.current_page,
    required this.stu_name,   //需要全局获取用户名,以回到Profile_edit页面时可以显示
  });

  @override
  Widget build(BuildContext context) {
    return Drawer(
      backgroundColor: Theme.of(context).colorScheme.surface,
      child: Column(
        //设置侧边栏为列式布局
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          //设置侧边栏内内容
          Column(
            children: [
              DrawerHeader(
                child: Center(
                  //设置中间对齐对象
                  child: Image.asset(
                    "lib/images/northwest_minzu_university_icon.png",
                    width: 100,
                    height: 100,
                  ),
                ),
              ),

              const SizedBox(height: 25), //设置控件间间隔

              //设置个人资料页面跳转按钮
              MyListTile(
                text: "个人资料", 
                icon: Icons.person, 
                onTap: () {
                  if (current_page=="/home_page")  //判断如果已经在目标跳转的页面
                    {
                      Navigator.pop(context);  //那么只关闭侧边栏,不触发动画
                    }
                  else
                    {
                      //弹出当前页面
                      Navigator.pop(context);
                      //跳转到主页
                      Navigator.push(
                        context, 
                        MaterialPageRoute(  //跳转到首页并给首页传入用户名
                          builder:(context)=>HomePage_Mobile(stu_name: stu_name,), 
                        ),
                      );
                    }                 
                }
              ),

              const SizedBox(height: 15), //设置控件间间隔

              //设置获奖资料编辑页面跳转按钮
              MyListTile(
                text: "编辑获奖信息",
                icon: Icons.edit,
                onTap: () {
                  if (current_page=="/profile_edit_page")  //判断如果已经在目标跳转的页面
                    {
                      Navigator.pop(context);   //那么只关闭侧边栏,不触发动画
                    }
                  else
                    {
                      //弹出当前页面
                      Navigator.pop(context);
                      //跳转到目标页面
                      Navigator.push(
                        context, 
                        MaterialPageRoute(
                          builder:(context)=>ProfileEdit_Mobile(stu_name: stu_name,),   //给个人资料页面传入用户名 
                        ),
                      );
                    } 
                },
              ),

              const SizedBox(height: 15), //设置控件间间隔

            ],
          ),

          Padding(
            padding: const EdgeInsets.only(bottom: 13.0),
            child: MyListTile(
              text: "关于本程序", 
              icon: Icons.info, 
              onTap: () {
                //弹出当前页面
                Navigator.pop(context);
                //跟随路由跳转至关于界面
                Navigator.pushNamed(context, "/about_page",);
              },
            ),
          ),
        ],
      ),
    );
  }
}
